package arnaldoTestandoConeccao;

import org.hibernate.HibernateException;
import org.hibernate.Session;

public class CriarUsuario {

	public static void createUser(String username) throws HibernateException {
		//Session session = factory.openSession();
		Session session = new HibernateFactory().getSession();
		try {
		session.beginTransaction();
		// Normal usage of the Session here...
		Produto p = new Produto();
		p.setNome("Desc");
		p.setDescricao(username);
		p.setPreco(100.0);

		session.saveOrUpdate(p);
		// Commit the transaction
		session.getTransaction().commit();
		} catch (HibernateException e1) {
		session.getTransaction().rollback();
		throw e1;
		} finally {
		// Close the session
		 session.close(); //close(session);
		}
		}
}
